import pandas as pd
import matplotlib.pyplot as plt
import descartes
import geopandas as gpd
from shapely.geometry import Point, Polygon
import plotly.express as px
%matplotlib inline
points = pd.read_csv("D:/KyotoProject/plot/testPoint.csv")
points_1809 = pd.read_csv("D:/KyotoProject/plot/export_plot.csv")
points.head()
points_1809.head()
#Insert unique index in the dataframe
def insertIndex(df, index = 'uid'):
"""trasfer 'uid' in the data to integer unique ID, added into the 'idIndex' column.
df = data frame file
index = the columne name of the dataframe you want to use to generate the unique index, default value = 'uid'
"""
nameList = list(df[index].unique())
print("number of the unique index value: ",len(nameList))
length = len(df)
k = []
for item in range(length):
i = nameList.index(df['uid'][item])
k.append(i)
df['idIndex'] = k
print(df.head())
return df
plot_1809 = insertIndex(points_1809, index = 'uid')
plot_1809.head()
#points_test = points[50:200]
#points_test = points_1809[0:20000]
#select the data points with specific 'idIndex'
filterList = list(range(0,100)) # select the frist 50 idindex of points
points_test = plot_1809[plot_1809['idIndex'].isin(filterList)]
print(len(points_test),'points')
points_test.head()
token = "https://api.mapbox.com/tokens/v2/haomingyang?access_token=sk.eyJ1IjoiaGFvbWluZ3lhbmciLCJhIjoiY2szOGd6OWEwMDhxaTNjcnRxYXl2eXJ1ayJ9.IekZ9PZJeaVKaZqtHGTooQ" # you will need your own token
fig = px.scatter_mapbox(points_test, lat="longitude", lon="latitude", hover_name="idIndex", hover_data=["month", "day", "hour", "minute"],
color_discrete_sequence=["fuchsia"], zoom=6, height=800, color="idIndex", size = "month", size_max = 6, color_continuous_scale=px.colors.cyclical.IceFire)
fig.update_layout(mapbox_style="open-street-map")
#fig.update_layout(mapbox_style="dark", mapbox_accesstoken=token)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()
token = "pk.eyJ1IjoiaGFvbWluZ3lhbmciLCJhIjoiY2szOGd2amIyMDllZzNjcWpqNnF6MjU0YyJ9.2dKHbwUYHrGe_V2bv0RXaQ" # you will need your own token
fig = px.scatter_mapbox(points_test, lat="longitude", lon="latitude", hover_name="idIndex", hover_data=["month", "day", "hour", "minute"],
color_discrete_sequence=["fuchsia"], zoom=6, height=1000, color="idIndex", size = "hour", size_max = 5, color_continuous_scale=px.colors.cyclical.IceFire)
#fig.update_layout(mapbox_style="open-street-map")
fig.update_layout(mapbox_style="dark", mapbox_accesstoken=token)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()
#select the data points with specific 'idIndex'
filterList = list(range(0,1)) # select the frist 50 idindex of points
points_test = plot_1809[plot_1809['idIndex'].isin(filterList)]
print(len(points_test),'points')
points_test.head()
token = "pk.eyJ1IjoiaGFvbWluZ3lhbmciLCJhIjoiY2szOGd2amIyMDllZzNjcWpqNnF6MjU0YyJ9.2dKHbwUYHrGe_V2bv0RXaQ" # you will need your own token
fig = px.scatter_mapbox(points_test, lat="longitude", lon="latitude", hover_name="idIndex", hover_data=["month", "day", "hour", "minute"],
color_discrete_sequence=["fuchsia"], zoom=6, height=1000, color="idIndex", size = "hour", size_max = 10,
color_continuous_scale=[[0, "rgb(166,206,227)"],
[0.25, "rgb(31,120,180)"],
[0.45, "rgb(178,223,138)"],
[0.65, "rgb(51,160,44)"],
[0.85, "rgb(251,154,153)"],
[1, "rgb(227,26,28)"]])
#fig.update_layout(mapbox_style="open-street-map")
fig.update_layout(mapbox_style="dark", mapbox_accesstoken=token)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()
#select the data points with specific 'idIndex'
filterList = list(range(3,10)) # select the frist 50 idindex of points
points_test = plot_1809[plot_1809['idIndex'].isin(filterList)]
print(len(points_test),'points')
points_test.head()
points_plot = points_test.query("day in [1,2,3,4,5]")
#points_plot = points_test
fig = px.line_mapbox(points_plot, lat="longitude", lon="latitude", color="idIndex", zoom=8, height=800)
fig.update_layout(mapbox_style="dark", mapbox_accesstoken=token)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()
len_item = len(dots['idIndex'].unique())
for i in range(len_item):
temp = points_plot[points_plot.idIndex ==dots['idIndex'].unique()[i]]
if i == 0:
fig = go.Figure(go.Scattermapbox(
mode = "markers+lines",
lon = temp['latitude'],
lat = temp['longitude'],
marker = {'size': 10}))
else:
fig.add_trace(go.Scattermapbox(
mode = "markers+lines",
lon = temp['latitude'],
lat = temp['longitude'],
marker = {'size': 10}))
fig.update_layout(
margin ={'l':0,'t':0,'b':0,'r':0},
mapbox = {
'center': {'lon': 135, 'lat': 35},
#The built-in plotly.js styles objects are: open-street-map, white-bg, carto-positron, carto-darkmatter,
#stamen-terrain, stamen-toner, stamen-watercolor
'style': "open-street-map",
'center': {'lon': -20, 'lat': -20},
'zoom': 1})
fig.show()